package com.team8.system.service.controller;

import com.team8.common.results.Result;
import com.team8.system.pojo.Person;
import com.team8.system.service.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("person")
public class PersonController {

    @Autowired
    private PersonService personService;


    @GetMapping("addperson")
    private ResponseEntity<Result> addPerson(
        @RequestParam("id_card") String idCard,
        @RequestParam("email") String email,
        @RequestParam("user_id") Integer userId,
        @RequestParam("person_name") String personName,
        @RequestParam("gender") String gender
    ){
        Person person = new Person(idCard, email, userId, personName, gender);

        Result result = personService.addPerson(person);

        return ResponseEntity.ok(result);
    }

    @GetMapping("get_user_persons")
    private ResponseEntity<List<Person>> getUserPersons(@RequestParam("user_id") Integer userId){

        List<Person> persons = personService.getUserPersons(userId);

        return ResponseEntity.ok(persons);
    }
}
